<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>资源</title>
<jsp:include page="../../import.jsp" flush="true" />
</head> 

<body class="iframeBody">
<div class="Wrapper">
    <table class="sq-formTable">
        <tbody>
            <tr>
                <td width="50%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            
                            <form id="searchBar2" class="titSearchBar">
                                <div class="fieldset1 clearFix">
                                    <div class="fieldBox">
                                        <div class="label">资源名称</div>
                                            <div class="field">
                                                 <input name="resNm" id="resNm" type="text" class="ui-textbox" value="" ligerui="width: 140">
                                            </div>
                                        </div>
                                    <span id="searchBtn2" class="sq-search-button"></i>查询</span>
                                </div>
                            </form>
                        </div>
                        <div class="sqPanel_body" style="min-height: 300px;">
                            <div class="btnsBox">
                                <!-- <span class="sq-button sq-button-hasicon" id="addPlat_button"><i class="sqBtnIco_3"></i>新增平台</span>
                                <span class="sq-button sq-button-hasicon" id="remove_button"><i class="sqBtnIco_7"></i>删除</span>
                                <span class="sq-button sq-button-hasicon" id="reloadTree_btn"><i class="sqBtnIco_28"></i>更新</span>
                                <span class="sq-button sq-button-hasicon onlyicon" title="上移"><i class="sqBtnIco_9"></i></span>
                                <span class="sq-button sq-button-hasicon onlyicon" title="下移"><i class="sqBtnIco_8"></i></span>
                                <span class="sq-button sq-button-hasicon onlyicon" id="demotion_btn" title="降级"><i class="sqBtnIco_17"></i></span>
                                <span class="sq-button sq-button-hasicon onlyicon" id="upgrade_btn" title="升级"><i class="sqBtnIco_18"></i></span> -->
                            </div>
                            <ul id="tree1">
                            </ul>
                        </div>
                    </div>
                </td>
                <td width="50%" valign="top">
                    <div class="sqPanel">
                        <div class="sqPanel_head">
                            <span><i class="sqIco sqIco_4"></i>资源详细</span>
                        </div>
                        <div class="sqPanel_body">
                            <div class="btnsBox">
<!--                                 <span class="sq-button sq-button-hasicon" id="change_btn"><i class="sqbtnico_4"></i>修改</span> -->
<!--                                 <span class="sq-button sq-button-hasicon" id="savechange_btn"><i class="sqbtnico_10"></i>保存</span> -->
<!--                                 <span class="sq-button sq-button-hasicon hide" id="savenew_btn"><i class="sqbtnico_3"></i>保存</span> -->
                            </div>
                            <form id="sysOrg_form" class="Hide">
                            <input name="pid" id="pid" type="text" style="display: none;" value=""/>
                            <input name="oid" id="oid" type="text" style="display: none;" value=""/>
                                <div class="fieldset1 tabel_col tabel_col_1 clearFix">
                                    <div class="fieldBox col_1_100">
                                        <div class="label">架构名称</div>
                                        <div class="field">
                                            <input name="orgNm" id="orgNm" type="text" class="ui-textbox" value="">
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">架构简称</div>
                                        <div class="field">
                                            <input name="orgShtNm" id="orgShtNm" type="text" class="ui-textbox" value="">
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">架构显示名称</div>
                                        <div class="field">
                                            <input name="orgDispNm" id="orgDispNm" type="text" class="ui-textbox" value="">
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">排序编号</div>
                                        <div class="field">
                                            <input name="sortNo" id="sortNo" type="text" class="ui-textbox" value="">
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">上级架构</div>
                                        <div class="field">
                                            <input name="parOrgDispNm" id="parOrgDispNm" type="text" class="ui-textbox" value="" readonly>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">架构类型</div>
                                        <div class="field">
						                    <select name="orgTypCd" id="orgTypCd">
						                        <option value=" " seleted>请选择</option>
						                       <c:forEach items="${searchSelectOrgTypCdList }" var="orgTypCdList">
						                        	<option value="${orgTypCdList.key }">${orgTypCdList.value }</option>
						                        </c:forEach>
						                    </select>
						                </div>
                                    </div>
                                     <div class="fieldBox col_1_100">
                                        <div class="label">描述</div>
                                        <div class="field" style="width: 100%;">
                                            <textarea name="StNotes" id="StNotes" rows="4" class="l-textarea" style="width:100%"></textarea>
                                        </div>
                                    </div> 
                                </div>
                                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                            </form>
                            <div id="sysOrg_form_t">
                                <div class="fieldset1 tabel_col tabel_col_1 clearFix">
                                    <div class="fieldBox col_1_100">
                                        <div class="label">资源名称</div>
                                        <div class="field">
                                            <span id="resNm_text"></span>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">资源类型</div>
                                        <div class="field">
						                    <span id="resTypCdNm_text"></span>
						                </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">URL</div>
                                        <div class="field">
                                        	<span id="resUrl_text"></span>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">排序</div>
                                        <div class="field">
                                            <span id="sortNo_text"></span>
                                        </div>
                                    </div>
                                    <div class="fieldBox col_1_100">
                                        <div class="label">是否有效</div>
                                        <div class="field">
                                            <span id="isValidNm_text"></span>
                                        </div>
                                    </div>
                                    
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>



<script type="text/javascript">

var tree,
    treeMenu,
    treeMenu2,
    actionNode;  //鼠标右击时的节点
$(function () {
    treeMenu = $.ligerMenu({
        top: 100,
        left: 100,
        width: 120,
        items:[
            { text: '添加子级架构', click: addChildNode, icon: 'addSubLevel' }
        ]
    });
    treeMenu2 = $.ligerMenu({
        top: 100,
        left: 100,
        width: 120,
        items:[
            { text: '添加同级架构', click: addPeerNode, icon: 'addSameLevel' },
            { text: '添加子级架构', click: addChildNode, icon: 'addSubLevel' }
           
        ]
    });
    tree = $("#tree1").ligerTree({
    	url: '<%=path%>/system/sysResource/initList.do',
        ajaxType: 'get',
        checkbox: false,
        isExpand: false, 
        parentIcon: "SqFolder",
        childIcon: "SqLeaf",
        needCancel:false,
        iconClsFieldName: "iconClass",
        onContextmenu: function (node, e) {
            actionNode=node;
            var parentNode = tree.getParent(node);
            if (parentNode) {
                //treeMenu.hide();
                //treeMenu2.show({ top: e.pageY, left: e.pageX });
            }else{  //没有父节点，那就是根节点
               // treeMenu2.hide();
               // treeMenu.show({ top: e.pageY, left: e.pageX });
            };
            return false;
        },
        onSelect: onSelectTree,
        onCancelselect: function (data,target) {
        	 $("#sysOrg_form").addClass('Hide');
             $("#sysOrg_form_t").removeClass('Hide');
        },
        onSuccess: function (data) {
            // 初始化的时候默认选中某个树节点
           /*  var selectNode_parm = function (treeData){
                return treeData.text == '节点1';
            };
            tree.selectNode(selectNode_parm); */
            
            tree.selectNode(data[0]);
        },
        
    });
    /* function upgrade_treeNode () {
        var parentNode = tree.getParent(actionNode);
        if (!parentNode) {
            var dialog = $.ligerDialog.warn("不能再升级了！");
            setTimeout(function () {dialog.close()}, 1500);
            return false;
        };
        alert("------升级------"+ "\n" +JSON.stringify(actionNode));
    }
    function demotion_treeNode () {
        var childrenNode = actionNode.data.children;
        if (!childrenNode) {
            var dialog = $.ligerDialog.warn("不能再降级了！");
            setTimeout(function () {dialog.close()}, 1500);
            return false;
        };
        alert("------降级------"+ "\n" +JSON.stringify(actionNode));
        //Ajax提交要升降级的Node，即selectedNode
        tree.reload();
    } */
    
    $("#searchBar2").ligerForm();
    $("#searchBtn2").click(function() {
        var form = liger.get("searchBar2");
        var data = form.getData();
        //alert(JSON.stringify(data));
        
        searchResource(data);
    });
    $("#change_btn").click(function(event) {
    	var selectedTree_node=tree.getSelected();
        if (!selectedTree_node) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_BEFORE,SQ_type: "warning"});
            return;
        }
        changeForm();
        
        $.ajax({
  			type: 'get',
  			dataType:'json',
  			data:{id:idEdit},
  			url: '<%=path%>/system/sysResource/getById.do',
  			success:function(msg){
  				 if(msg.success == 1){
  					
  					setValueToInput(msg.data)
  					 
  				 }else{
  					 
  				 }
  			}
  		});
        
    });
    $("#remove_button").click(function(event) {
    	var selectedTree_node=tree.getSelected();
    	alert(JSON.stringify(selectedTree_node));
        if (!selectedTree_node) {
        	 top.$.ligerDialog.SQalert({content: LogUtils.LOG_SYS_ORG_SELECT_BEFORE,SQ_type: "warning"});
            return;
        }
        
        $.ligerDialog.confirm('连同该架构下的子架构及人员数据权限也将被删除，是否确认删除？', function (flag) {
			if(flag == false)return;
			$.ajax({
	  			type: 'get',
	  			dataType:'json',
	  			data:{id:selectedTree_node.data.id},
	  			url: '<%=path%>/system/sysOrg/removeById.do',
	  			success:function(msg){
	  				 if(msg.success == 1){
	  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	  				 }else{
	  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	  				 }
	  			}
	  		});
		});
    });
    $("#addPlat_button").click(function(event) {
    	 $("#resetBtn").click();
    	swithBtn()
        changeForm();
    });
    
    $("#reloadTree_btn").click(function(event) {
        tree.reload();
    });
   
    $("#saveNew_btn").click(function(event) {
    	var form = new liger.get("sysOrg_form");
  	    var data = form.getData();
  	    
  	   // alert(JSON.stringify(data));
  	   
  	    $.ajax({
  			type: 'post',
  			dataType:'json',
  			data:data,
  			url: '<%=path%>/system/sysOrg/add.do',
  			success:function(msg){
				$(this).addClass("Hide");
		    	$(this).siblings(".sq-button").removeClass("Hide");
  				 if(msg.success == 1){
  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
  				 }else{
  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
  				 }
  			}
  		});
    });
    var idEdit;
    function changeForm () {
        $("#sysOrg_form_t").addClass('Hide');
        $("#sysOrg_form").removeClass('Hide');
        setForm();
       
    }
    function detailForm () {
        $("#sysOrg_form").addClass('Hide');
        $("#sysOrg_form_t").removeClass('Hide');
    }
    function onSelectTree (node) {
    	$("#saveNew_btn").addClass("Hide");
    	$("#saveNew_btn").siblings(".sq-button").removeClass("Hide");
        //console.log(node.data);
        //alert(JSON.stringify(node));
        detailForm ()
        
         $.ajax({
  			type: 'get',
  			dataType:'json',
  			data:{id:node.data.id},
  			url: '<%=path%>/system/sysResource/getById.do',
  			success:function(msg){
  				 if(msg.success == 1){
  					setValueToText(msg.data);
  					idEdit =msg.data.id;
  				 }else{
  					 
  				 }
  			}
  		});
    }
    function treeMenu_handler_1 (item, i) {
        alert(item.text+ "\n" +JSON.stringify(item)+ "\n" +actionNode.data.text+ "\n" +JSON.stringify(actionNode));
        console.log(item, i, actionNode);
    }
    //添加子级架构
    function addChildNode (){
    	 $("#resetBtn").click();
    	 swithBtn();
    	var id = actionNode.data.id;
    	var text=actionNode.data.text;
    	changeForm();
    	$("#parOrgDispNm").val(text);
    	$("#pid").val(id);
    	
    	
    }
  //添加同级架构
    function addPeerNode (){
    	 $("#resetBtn").click();
    	 swithBtn();
    	var pid = actionNode.data.pid;
    	
    	changeForm();
    	  $.ajax({
    			type: 'get',
    			dataType:'json',
    			data:{id:pid},
    			url: '<%=path%>/system/sysOrg/getById.do',
    			success:function(msg){
    				 if(msg.success == 1){
    					 $("#parOrgDispNm").val(msg.data.orgNm);
    				 }else{
    					 
    				 }
    			}
    		});
    	$("#pid").val(pid);
    }
  	//修改中的保存按钮
     $("#saveChange_btn").click(function(){
   		
    	var form = new liger.get("sysOrg_form");
  	    var data = form.getData();
  	    
  	   // alert(JSON.stringify(data));
  	   
  	    $.ajax({
  			type: 'post',
  			dataType:'json',
  			data:data,
  			url: '<%=path%>/system/sysOrg/modify.do',
  			success:function(msg){
  				 if(msg.success == 1){
  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
  				 }else{
  					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
  				 }
  			}
  		});
  	});

	 function setForm(){
	    $("#sysOrg_form").ligerForm({
	        validate: true
	    }); 
	 }
	 function swithBtn(){
		 $("#saveNew_btn").removeClass("Hide");
	     $("#saveNew_btn").siblings(".sq-button").addClass("Hide");
	 }
	 //赋值方法到详细
	 function setValueToText(data){
		$("#resNm_text").text(isNulltoNBSP(data.resNm));
        $("#resTypCdNm_text").text(isNulltoNBSP(data.resTypCdNm));
        $("#resUrl_text").text(isNulltoNBSP(data.resUrl));
        $("#sortNo_txt").text(isNulltoNBSP(data.sortNo));
        $("#isValidNm_text").text(isNulltoNBSP(data.isValidNm));
	 }
	 //赋值方法到输入框
	 function setValueToInput(data){
        $("#oid").val(data.id);
		 var form = new liger.get("sysOrg_form");
			form.setData({
				orgTypCd:data.orgTypCd,
			});
        $("#orgNm").val(isNulltoNBSP(data.orgNm));
        $("#orgShtNm").val(isNulltoNBSP(data.orgShtNm));
        $("#orgDispNm").val(isNulltoNBSP(data.pidNm));
        $("#sortNo").val(isNulltoNBSP(data.sortNo));
        $("#parOrgDispNm").val(isNulltoNBSP(data.pidNm));
        
	 }
	 function isNulltoNBSP(a){
			if(a==null || a==undefined){
				return ""
			}else{
				return a;
			}
		}
});
    
function searchResource (parm) {
    $.ajax({
    	url: '<%=path%>/system/sysRoleResR/getByResNm.do',
        type: 'GET',
        dataType: 'json',
        data: parm,
        success: function (result) {
            tree.setData(result.data.data);
        }
    });
}

</script>

</body>
</html>

</body>
</html>